// pages/set/feedback/feedback.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: [],
		http:getApp().globalData.map
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
			}
		})
	},
	sc() {
		let a = this.data.list
		if (a.length < 9) {
			let nan=9-a.length
			wx.showToast({
				title: '加载中',
				icon: 'loading'
			});
			let that = this
			wx.chooseImage({
				count: nan,
				sizeType: 'compressed',
				success: (e) => {
					e.tempFilePaths.forEach(function(item, index) {
						wx.uploadFile({
							url: getApp().globalData.http3,
							filePath: e.tempFilePaths[index],
							name: 'picturePath',
							success: function(res) {
								let c = JSON.parse(res.data)
								a.push(c.data.headImage)
								that.setData({
									list: a
								})
								wx.hideToast();
							}
						});
					})
				}
			})
		}
	},
	dete(e) {
		let a = this.data.list
		a.splice(e.currentTarget.dataset.id, 1)
		this.setData({
			list: a
		})
	},
	nav() {
		if (this.data.value == undefined) {
			wx.showToast({
				icon: 'none',
				title: '请输入反馈内容'
			})
		} else {
			let hiso = []
			let that = this
			wx.showToast({
				title: '加载中',
				icon: 'loading'
			});
			this.data.list.forEach(function(item, index) {
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath: item,
					name: 'picturePath',
					success: (e) => {
						let a = JSON.parse(e.data)
						hiso.push(a.data.headImage)
						let sin = hiso.join(',')
						console.log(sin)
						that.setData({
							sc: sin
						})
					}
				})
			})
			setTimeout(function() {
				wx.request({
					url: getApp().globalData.http + 'action=addFeedBack&nr=' + that.data.value + '&imgUrl=' + that.data.sc +
						'&uid=' + that.data.uid,
					success: (e) => {
						wx.showToast({
							title: '反馈成功',
							icon: 'none',
							success: (e) => {
								wx.navigateBack({
									delta: 1
								})
							}
						})
						wx.hideToast();
					}
				})
			}, 1000)
		}
	},
	value(e) {
		this.setData({
			value: e.detail.value
		})
	}
})
